package com.summer.utils.file.impl;

import com.summer.utils.file.DeleteFileService;

import java.io.File;

public class DeleteFileServiceImpl implements DeleteFileService {

    @Override
    public void delJustAllFile(String path) {
        boolean flag = false;
        File file = new File(path);
        if (!file.exists()) {
            throw new RuntimeException("文件不存在");
        }
        if (!file.isDirectory()) {
            throw new RuntimeException("该文件不是目录");
        }
        String[] tempList = file.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
            if (path.endsWith(File.separator)) {
                temp = new File(path + tempList[i]);
            } else {
                temp = new File(path + File.separator + tempList[i]);
            }
            if (temp.isFile()) {
                temp.delete();
            }
        }

    }

    @Override
    public void delJustAllFile(File file) {

        delJustAllFile(file.getAbsolutePath());
    }
}
